package typeConversion

import (
	"errors"
	"fmt"
	"strconv"
	"time"
)

//in string、int、float、time.time
func ToInt64(p_in interface{}) (int64, error) {
	if p_in == nil {
		return 0, errors.New("too.typeConversion ToInt err: Parameters not supported, Parameters is nil")
	}
	switch p_in.(type) {
	case string:
		return strconv.ParseInt(p_in.(string), 10, 64)
	case int:
		return int64(p_in.(int)), nil
	case int32:
		return int64(p_in.(int32)), nil
	case int64:
		return p_in.(int64), nil
	case float32:
		return int64(p_in.(float32)), nil
	case float64:
		return int64(p_in.(float64)), nil
	case time.Time:
		return p_in.(time.Time).Unix(), nil
	default:
		return 0, errors.New("too.typeConversion ToInt64 err: Parameters not supported,The parameter type is " + fmt.Sprintf("%T", p_in))
	}
}
